/*
 * @Author: your name
 * @Date: 2022-03-13 11:01:04
 * @LastEditTime: 2025-07-29 13:12:12
 * @LastEditors: 小白
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \tmsadmin\src\store\index.ts
 */
import { createStore, Store, useStore as baseUseStore } from 'vuex'
import { InjectionKey } from 'vue'
import createPersistedState from 'vuex-persistedstate'
const state = {
  isCollapse: false,
  userInfo: null,
  menuList: [],
  currPath: '/',
  avatar: '',
  mobile: '',
  password: '207cf410532f92a47dee245ce9b11ff71f578ebd763eb3bbea44ebd043d018fb',
}
export type State = typeof state
// 定义一个InjectionKey
export const key: InjectionKey<Store<State>> = Symbol('store')
// 创建一个新的 store 实例
export const store = createStore<State>({
  state,
  mutations: {
    setCurrPath(state, payload) {
      state.currPath = payload
    },
    setAvatar(state, payload) {
      state.avatar = payload
    },
    setMobile(state, payload) {
      state.mobile = payload
    },
    setPassword(state, payload) {
      state.password = payload
    },
    setIsCollapse(state, payload) {
      state.isCollapse = payload
    },
    setUserInfo(state, payload) {
      state.userInfo = payload
    },
    setMenuList(state, payload) {
      state.menuList = payload
    },
  },
  plugins: [
    createPersistedState({
      // storage: window.sessionStorage
      storage: window.localStorage,
    }),
  ],
})

export function useStore() {
  return baseUseStore(key)
}
